package game.kcp;

import game.scene.msg.SMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

/**
 * @author : [zhaojianbo]
 * @version : [v1.0]
 * @className : [KcpUtils]
 * @description :KcpUtils
 * @createTime : 2025/6/26
 */
public class KcpUtils {

    public static void sendMsg(KcpOnUdp kcp,SMessage sMsg){
        byte[] body = sMsg.getData();
        int bodyLen = body == null ? 0 : body.length;
        int contentLength = bodyLen + 4;
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();


        buffer.writeInt(contentLength);
        buffer.writeInt(sMsg.getId());
        if (body != null) {
            //protobuf数据
            buffer.writeBytes(body);
        }
        kcp.send(buffer);
    }
}
